import request from "@/utils/request";
import type { CategoryList } from "./model/categoryModel";

const enum Api {
  getCategory1List = "/admin/product/getCategory1",
  getCategory2List = "/admin/product/getCategory2",
  getCategory3List = "/admin/product/getCategory3",
  addCategory1 = "/admin/product/saveCategory1",
  addCategory2 = "/admin/product/saveCategory2",
  addCategory3 = "/admin/product/saveCategory3",
  updateCategory1 = "/admin/product/updateeCategory1",
  updateCategory2 = "/admin/product/updateeCategory2",
  updateCategory3 = "/admin/product/updateeCategory3",
  removeCategory1 = "/admin/product/removeCategory1",
  removeCategory2 = "/admin/product/removeCategory2",
  removeCategory3 = "/admin/product/removeCategory3",
}

/**
 * 获取一级分类列表
 * @returns CategoryList
 */
export const getCategory1ListApi = () => {
  return request.get<any, CategoryList>(Api.getCategory1List);
};

/**
 * 获取二级分类列表
 * @returns CategoryList
 */
export const getCategory2ListApi = (category1Id: number) => {
  return request.get<any, CategoryList>(
    Api.getCategory2List + `/${category1Id}`
  );
};

/**
 * 获取三级分类列表
 * @returns CategoryList
 */
export const getCategory3ListApi = (category2Id: number) => {
  return request.get<any, CategoryList>(
    Api.getCategory3List + `/${category2Id}`
  );
};

/**
 * 添加一级分类
 * @param name 分类名称
 * @returns null
 */
export const addCategory1Api = (name: string) => {
  return request.post<any, null>(Api.addCategory1, { name });
};

/**
 * 添加二级分类
 * @param name 分类名称
 * @param category1Id 一级分类id
 * @returns null
 */
export const addCategory2Api = (name: string, category1Id: number) => {
  return request.post<any, null>(Api.addCategory2, { category1Id, name });
};

/**
 * 添加三级分类
 * @param name 分类名称
 * @param category2Id 二级分类id
 * @returns null
 */
export const addCategory3Api = (name: string, category2Id: number) => {
  return request.post<any, null>(Api.addCategory3, { category2Id, name });
};

/**
 * 更新一级分类
 * @param id 分类id
 * @param name 分类名称
 * @returns null
 */
export const updateCategory1Api = (id: number, name: string) => {
  return request.put<any, null>(Api.updateCategory1, { id, name });
};

/**
 * 更新二级分类
 * @param id 分类id
 * @param name 分类名称
 * @returns null
 */
export const updateCategory2Api = (id: number, name: string) => {
  return request.put<any, null>(Api.updateCategory2, { id, name });
};

/**
 * 更新三级分类
 * @param id 分类id
 * @param name 分类名称
 * @returns null
 */
export const updateCategory3Api = (id: number, name: string) => {
  return request.put<any, null>(Api.updateCategory3, { id, name });
};

/**
 * 删除一级分类
 * @param id 分类id
 * @returns null
 */
export const removeCategory1Api = (id: number) => {
  return request.delete<any, null>(Api.removeCategory1 + `/${id}`);
};

/**
 * 删除二级分类
 * @param id 分类id
 * @returns null
 */
export const removeCategory2Api = (id: number) => {
  return request.delete<any, null>(Api.removeCategory2 + `/${id}`);
};

/**
 * 删除三级分类
 * @param id 分类id
 * @returns null
 */
export const removeCategory3Api = (id: number) => {
  return request.delete<any, null>(Api.removeCategory3 + `/${id}`);
};
